<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>蒋路的ic到申请检查</title>
</head>
		
<body>

	<script type="text/javascript"> 
	
	function chkmaxsms(vobj1,vmax)   {  
		 var str=vobj1.value;  
		 var strlen=str.length;
		 var vv=vmax-strlen;
		if(strlen>vmax)   {  
		  $("#cc_show_dnameshu")
			.html("你已经输入了："+vmax+"个字，还可以输入0个字！");
		  $.messager.alert("提示", "您已经超出该文本的输入范围，系统将只截取有效范围内的字符！");
		  $("#cc_input_dname").val(vobj1.value=str.substr(0,vmax));
		}else{
			$("#cc_show_dnameshu")
			.html("你已经输入了："+strlen+"个字，还可以输入"+vv+"个字！");
			
		}
	} 
	
	$(function(){	
		var ieId="";
		//var ieId='${ieId}';
		//alert("ieId"+ieId);		
		var pid='${pid}';
		//alert(pid);
		if(pid!=null || pid!=""){
			$("#ExamineApplytab").datagrid({
				 url: 'pidtoexamineapply?pid='+pid 
			});
		}else if(pid==null || pid==""){
			$("#ExamineApplytab").datagrid({
				 url: 'icidtoexamineapply?ieId='+ieId 
			});
		}
			var date = new Date();		
			var y = date.getFullYear();  
			var m = date.getMonth() + 1;  
			m = m < 10 ? '0' + m : m;  
			var d = date.getDate();  
			d = d < 10 ? ('0' + d) : d;  
			var needDate=y + '-' + m + '-' + d;  	
			 
			$("#idToExaminCharge_begin").linkbutton({
				onClick:function(){					
					var rows = $("#ExamineApplytab").datagrid("getSelections");					
					if(rows.length == 1){
						var rowIndex=$('#ExamineApplytab').datagrid('getRowIndex',$('#ExamineApplytab').datagrid('getSelected'))
						var row = $('#ExamineApplytab').datagrid('getData').rows[rowIndex];
						if(row.state=="完成"){
							 $.messager.alert("温馨提示","检查已经完成！");
						}else{						
							$('#idToExaminApplywin').window({'title': "检查结果"});
							$("#idToExaminApplywin").window('open');													
						    var checkjg_ysid=$("#index_cprePerson").combobox("getText");
							$("#idToExaminApplyff").form("clear");
						    $("#icrId").textbox("setText",row.ieId);
						    $("#crFigurePerson").textbox("setText",checkjg_ysid);
						    $("#icrId").textbox("setValue",row.ieId);
						    $("#crFigurePerson").textbox("setValue",checkjg_ysid);
							$("#crCheckDate").textbox("setValue",needDate);
						}						
						
					}else{
						$.messager.alert("提示", "检查是个细致活需要一项一项来！你现在选择了" + rows.length + "项检查项!");
					}
				}
			});
			$("#idToExaminCharge_end").linkbutton({
				onClick:function(){					
					    var rows = $('#ExamineApplytab').datagrid('getRows')//获取当前页的数据行  
					    var total = 0;  
					    for (var i = 0; i < rows.length; i++) { 
					    	if(rows[i]['state']==null ||rows[i]['state']==""){
					    		total=total+1;				    		
					    	}		        
					    } 
					   if(total>0){
							$.messager.alert("温馨提示","你还有"+total+"项未检查");
					   } else{
						    $.messager.alert("温馨提示","结束检查！");
				    		$('#idtoexamineApplyWin').window('close')
					   }
				}
			});
			$("#idToExaminApply-save").linkbutton({  
				onClick : function() {
					var rows = $("#ExamineApplytab").datagrid("getSelections");
					$('#idToExaminApplyff').form('submit', {
						onSubmit : function() {
						},				
						success : function(data) {
							$.messager.alert("温馨提示", "检查完成");
							//关闭窗口
							$("#idToExaminApplywin").window('close');
							$(this).form("clear");
							        var eDate = rows[0].eDate;
							        var date = new Date(eDate);		
									var y = date.getFullYear();  
									var m = date.getMonth() + 1;  
									m = m < 10 ? '0' + m : m;  
									var d = date.getDate();  
									d = d < 10 ? ('0' + d) : d;  
									var needDate=y + '-' + m + '-' + d;							
									var eId = rows[0].eId;							
									var cpreId = rows[0].cpreId;
									var eOffice = rows[0].eOffice;
									var ePhysician = rows[0].ePhysician;
									var ieId = rows[0].ieId;
									var state="完成";
									$.ajax({
						                type: "Post",
						                url: "addExamineApply",
						                data: {eId: eId,
						                		cpreId:cpreId,
						                		eDate:needDate,
						                		eOffice:eOffice,
						                		ePhysician:ePhysician,
						                		ieId:ieId,
						                		state:state 
						                		},
						                success: function (data) {
						                	$("#ExamineApplytab").datagrid("reload");
						                	var sxsf=$("#tontyiStaffId").html();
						                	$.ajax({
						    	                type: "Post",
						    	                url: "to_idToTbstaff",
						    	                data: {staffNo:sxsf},
						    	                success: function (data) {
						    	                	$.ajax({
								                        type: "Post",
								                        url: "to_addJlCheckPaypage",
								                        data: {
								                        	     cpFigurePerson:data[0].staffName,
								                        	     cpDate:needDate,
																 cpNum:120,
																 icpId:ieId
																 
															  },	
								                        success: function (data) {
								                            
								                        }
								                    });
						    	                }
						    	            });
						                					                							                	
						                }
						            });																	
									
						}
					});
				}
			});
	});
	</script>
	

	<table id="ExamineApplytab" class="easyui-datagrid"
			data-options="
				fitColumns:true,
				fit:true,
				rownumbers: true,
				url: '', 
				border:false ,
				pagination:true,
				toolbar: '#idToExaminApply_btn',
				pageSize: 14,
				pageList:[14,28,42,56]
			">
			<thead>
				<tr>
					<th class="ident" data-options="field:'eId',checkbox:true">申请编号</th>
					<th class="ident" data-options="field:'ieId',width:10">IC卡号</th>
					<th class="ident" data-options="field:'eOffice',width:15,editor:'textbox'">科室</th>
					<th class="ident" data-options="field:'ePhysician'">医师</th>
					<th class="ident" data-options="field:'cpreId'">检查项目</th> 
					<th class="ident" data-options="field:'eDate',width:10,formatter:function(value){
                          var unixTimestamp = new Date(value);  
                          return unixTimestamp.toLocaleDateString();}">申请日期
                    </th> 
                    <th class="ident" data-options="field:'state'">状态</th> 
				</tr>
			</thead>
		</table>
		<div id="idToExaminApply_btn">
			<a id="idToExaminCharge_begin" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true">开始检查</a> 
			<a id="idToExaminCharge_end" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true">结束检查</a> 
		</div>
		
		<div>
		<div id="idToExaminApplywin" class="easyui-window"
			style="padding: 10px;line-height: 150%;"
			data-options="
		     width: 500,
		     height:360,
		     closed: true		     
			">		
				<form id="idToExaminApplyff" action="to_addJlCheckResult" method="post">
				<div id="checkJgOne"style="border:1px solid #95B8E7;background-color:#E0ECFF;margin-bottom:8px;height:75px;border-top-left-radius:5px;border-top-right-radius:5px; border-bottom-right-radius:5px;  border-bottom-left-radius:5px;">
					<table style="margin-top:9px;margin-left:8px;">
						<tr>
							<td>
								<div class="item">
									<input id="icrId" name="icrId"  class="easyui-textbox" data-options="label: '卡号:', width: 200,readonly:true,labelWidth:65">
								</div>
							</td>
							<td>
								<div class="item">
									<input id="crFigurePerson"  name="crFigurePerson"  class="easyui-textbox" data-options="label: '处理人:', readonly:true,width: 200,labelWidth:65">
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div class="item">
									<input id="crCheckDate"  name="crCheckDate" class="easyui-textbox" data-options="label: '检查日期:',readonly:true, width: 200,labelWidth:65">
								</div>
							</td>
							<td>
								<div class="item">
									<input id="crRemark"  name="crRemark" class="easyui-textbox" data-options="label: '备注:', width: 200,labelWidth:65">
								</div>
							</td>
						</tr>						
					</table>
					</div>
					<div class="item">	
					
						<div id="tt" class="easyui-tabs" style="width:466px;height:190px;">   
						    <div title="检查结果" style="display:none;">   
						       <div style="padding: 0px;">												
									<textarea id="crCheckResult" name="crCheckResult" style="height:130px;
										width:452px;margin-left:3px;
										border-top-right-radius:5px;
										border-top-left-radius:5px;
										border-bottom-right-radius:5px;
										border-bottom-left-radius:5px;"
										onkeyup="javascript:chkmaxsms(this,'999')"></textarea>							
								</div>
								<div id="cc_show_dnameshu" style="margin-left:210px;margin-top: 0px;padding: 0px;color:#666666; bottom:10px;">
								你已经输入了：0个字，还可以输入999个字！
								</div>  								   
						    </div>     
						</div> 																											
					</div>
					<div class="item"style="width:195px;margin-left:270px;">
							<a id="idToExaminApply-save" class="easyui-linkbutton"style="width:94px"data-options="iconCls:'icon-icNo'">确定</a>
							<a id="idToExaminApplycancel" class="easyui-linkbutton"style="width:94px"data-options="iconCls:'icon-icOk'">取消</a>
					</div>	
				</form>			
		</div>
	</div>
</body>
</html>